 <?php
    $id=$_REQUEST['id'];
         require_once '../action/DB_MySQL.php';
         $mysql = new DB_MySQL;
         $mysql->connect('localhost', 'baocao', 'root', '');   
        if(isset($_POST['change'])){
           $category=$_POST['cate'];
           $title=$_POST['title'];
           $primary=$_POST['elm1'];
           $noidung=htmlspecialchars_decode(mysql_real_escape_string($primary));
          
            $errors=array();
            if(!isset($title)|| empty($title)){
                $errors[]="Tiêu đề không được rổng";
            }
            if(!isset($primary)||empty($primary)){
                $errors[]="Nội dung không được rổng";
            }
            
            if(empty($errors)){
                $sql_query="UPDATE post set category='{$category}', title='{$title}',primary='{$noidung}'  WHERE id='{$id}'";
              
                $mysql->query($sql_query);
                
                  echo $sql_query;
                  
            }
            
        }
        if(!empty($errors)){
            foreach($errors as $error){
                echo "<ul>";
                  echo "<li>$error</li>";
                echo"</ul>";
            }
        }
        
        ?>

       <form action="index.php?id=<?php echo $id;?>" method="POST" id="change_form">
           
            <p>
              <label>Phân loại</label>
              <select name="cate">
              <?php
               $mysql->query("select * from post");
               while($row1=$mysql->fetchRow()){
                
               ?>
                    <option><?php echo $row1[category];?></option>
               <?php }?>
              </select>
            
            </p>
            
            <?php
                $mysql->query("select * from post where id='".$id."'");
                $row=$mysql->fetchRow();
            ?>
             <p>
               <label>Tiêu đề bài viết:</label>
               <input  type="text" value="<?php echo $row[title];?>" name="title"/>
            </p>
         	<textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%">
        		<?php
                  
                   echo $row[primary];
                 ?>
        	</textarea>
            
            <input type="submit" name="change" id="change_" value="Lưu" />
        </form>
